﻿using Futaba.SBus.Telemetry;
using Futaba.SBus.Telemetry.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Futaba.SBus.Tests.Telemetry
{
	partial class SlotValueParserTests
	{

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Temperature")]
		public void ParseTemperature_Temperature_Strip64()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 6;
			var parameter = GetParameter(_sensors, SensorType.TemperatureSensor, SensorValueType.Temperature);
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0x40, 0x06 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Temperature")]
		public void ParseTemperature_Temperature_Positive()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 6;
			var parameter = GetParameter(_sensors, SensorType.TemperatureSensor, SensorValueType.Temperature);
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0x00, 0x06 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Temperature")]
		public void ParseTemperature_Temperature_Negative()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = -3;
			var parameter = GetParameter(_sensors, SensorType.TemperatureSensor, SensorValueType.Temperature);
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0xFF, 0xFD },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

	}
}
